#pragma once
#include "../core/CUtil.h"
#ifdef __ANDROID__
	#include "android/AAssetMgr.h"
#endif

class PlatUtil {
public:
	static void readFileAsString(std::string& out, const std::string& filePath) {
		#ifdef __ANDROID__
			if (AAssetMgr::isValidAssetPath(filePath)) {
				AAssetMgr::get()->readFileAsString(out, filePath);
				return;
			}
		#endif
		CUtil::readFileAsString(out, filePath);
	}

	static void readFileAsBytes(CByteArray& out, const std::string& filePath) {
		#ifdef __ANDROID__
			if (AAssetMgr::isValidAssetPath(filePath)) {
				AAssetMgr::get()->loadAsset(out, filePath);
				return;
			}
		#endif
		CUtil::readFileAsBytes(out, filePath);
	}

	static void filesOfDir(std::vector<std::string>& outFileNames, const std::string& dirPath, const char* filterExtension = "", bool asc = true) {
		#ifdef __ANDROID__
			if (AAssetMgr::isValidAssetPath(dirPath)) {
				AAssetMgr::get()->filesOfDir(outFileNames, dirPath, filterExtension, asc);
				return;
			}
		#endif
		CUtil::filesOfDir(outFileNames, dirPath, filterExtension, asc);
	}

	static bool fileExists(const std::string& path) {
		#ifdef __ANDROID__
			if (AAssetMgr::isValidAssetPath(path))
				return AAssetMgr::get()->exists(path);
		#endif
		return CUtil::fileExists(path);
	}

private:
	PlatUtil() = default;
};